<template>
  <div class="SendOut">
    <div class="coent" style="font-size: 18px"></div>
  </div>
</template>
<script>
import { FileServerProxy } from "../../utils/api";
import dd from "gdt-jsapi";
export default {
  data() {
    return {
      items: [],
      ifID: "",
      TASK_ID: "",
      tableData: [],
      indexData: [],
      code1: "",
      xcfy: "",
      rowGuid: "",
    };
  },
  mounted() {
    if (ZWJSBridge) {
      ZWJSBridge.setTitle({
        title: "选择人员",
      })
        .then((res) => {
        })
        .catch((err) => {
        });
    }
  },
  methods: {
    getData: async function (data) {
      //自动批转  
      //获取发送人员的接口
      let params = {
        accessCode: "0a709d649c314903a72225edb8bc8c2a",
        
        params: {
          taskId: this.row.TASK_ID,
          direction: 0, //0是发送  1是打回
          token: window.localStorage.getItem("token"),
        },
      };
      const res = await FileServerProxy(params);
      let datasendForm = JSON.parse(res.data.data);
      this.tableData = datasendForm;
      //判断等级 发送不同的环节
      if (datasendForm.SendData && datasendForm.SendData.length > 0) {
        let paer = {
          procName: "USERNAME",
          dtParams: JSON.stringify([{ I_USERID: this.row.TASK_DISPATCHERID }]),
          token: window.localStorage.getItem("token"),
        };
        let procName = {
          accessCode: "69db6bece3a7480592e2ec753d1e335e",
          
          cityCode: window.localStorage.getItem("citycode") ? window.localStorage.getItem("citycode") : "441300000000",
          params: paer,
        };
        const res = await FileServerProxy(procName);
        let proData = JSON.parse(res.data.data);
        if (proData.Data && proData.Data.length > 0) {
          datasendForm.SendData.forEach((nodeItem, index) => {
            if (nodeItem.PTNID == -1) {
              var newItem = {};
              newItem.TNID = index;
              newItem.PTNID = nodeItem.TNID;
              newItem.TEXT = proData.Data[0].USERNAME;
              newItem.USERID = proData.Data[0].USERID;
              newItem.AUTOCHECKED = true;
              newItem.WFNODEGUID = nodeItem.WFNODEGUID;
              newItem.WFNODENAME = nodeItem.WFNODENAME;
              newItem.WFNODETYPE = nodeItem.WFNODETYPE;
              newItem.SINGLEASSIGN = nodeItem.SINGLEASSIGN;
              newItem.ISUSER = 1;
              this.indexData.push(newItem);
            }
          });
        }
      }
      this.handleGoToNext()
    },
    handleGoToNext: async function () {
      //判断当前是否选择了人员
      if (this.indexData.length > 0) {
        if (this.row.TASK_ID) {
          let plantask = {
            accessCode: "c52bcf7cf3fb42bb9fbcd9b91e97d411",
               cityCode: window.localStorage.getItem("citycode")
              ? window.localStorage.getItem("citycode")
              : "441300000000",
            params: {
              taskId: this.row.TASK_ID,
              direction: 0,
              wfGuid: this.tableData.ProcInfo.WF_GUID,
              sendNodes: JSON.stringify(this.indexData),
              actionText: "同意",
              taskName: this.row.NODE_NAME,
              token: window.localStorage.getItem("token"),
            },
          };
          const respl = await FileServerProxy(plantask);
          let data = JSON.parse(respl.data.data).Success;
          if (data) {
            this.$toast.success("成功！");
            setTimeout(() => {
              this.$router.push({
                path: "/CHMyTodoList",
              });
            }, 500);
          }
        }
      }
    },
  },
  mounted() {
    this.row = JSON.parse(this.$route.query.data)
    this.getData();
  },
};
</script>
<style lang="scss" scoped>
.SendOut {
  height: 100vh;
  background: #fff;
  font-size: 0.2em;
}
</style>
